-module(test1_1).
-include_lib("records.hrl").
-export([run/0]).

run() ->
  S1 = spawn(fun()->routerc:init(1) end),
  S2 = spawn(fun()->routerc:init(2) end),
  L1_2 = spawn(fun()->routeroutputline:init(1, 10, 1, 2, S2, 0)end),
  S1 ! {self(), {add_output, L1_2}},
  lists:foreach(fun(E) -> generate_packet(S1, E) end, [1,2,3,4,5,6,7,8,9,10,11,12]),
  run(S1, L1_2, 0),
  display(S1),
  sleep(1000),
  display(S2).

run(_, _, 1000) ->
  io:format("Time:~p~n", [1000]),
  finish;

run(S1, L1_2, Time) ->
  L1_2 ! {self(), {time_change, Time}},
  sleep(3),
  run(S1, L1_2, Time+1).

generate_packet(S1, I)->
  P = #packet{id=I, sources=[1,2], plength=10},
  S1 ! {self(), {packet, P}}.

sleep(T) ->
  receive
  after T ->
     true
  end.

display(S) ->
  S ! {self(), close}.
